Skip to content

feat(content-docs): allow autogenerated ID as fallback alias for explicit ID#11769

Open
fresh3nough wants to merge 1 commit intofacebook:mainfrom
fresh3nough:feat/autogenerated-id-alias
Open

feat(content-docs): allow autogenerated ID as fallback alias for explicit ID#11769
fresh3nough wants to merge 1 commit intofacebook:mainfrom
fresh3nough:feat/autogenerated-id-alias

Conversation

@fresh3nough
Copy link
Contributor

@fresh3nough fresh3nough commented Mar 3, 2026

Motivation

Closes #11691

When a document uses an explicit id in front matter, the autogenerated ID (derived from the file path) is completely replaced. This means any existing references that used the file-path-based ID break silently.

This PR proposes that the autogenerated ID be preserved as a fallback alias, so both the explicit ID and the file-path-based ID resolve to the same document.

Changes

  • Type: Added optional autoGeneratedId field to DocMetadataBase
  • Metadata: In doProcessDocMetadata, the file-path-based ID is computed and stored when the front matter id differs from the file name
  • Index: createDocsByIdIndex now registers autogenerated IDs as fallback entries (never overriding an explicit ID)
  • Tests: Added unit tests for autoGeneratedId computation and createDocsByIdIndex alias behavior
  • Snapshots: Updated 5 snapshots to reflect the new field on affected fixture docs

Test Plan

Ran the plugin test suite (docs.test.ts, index.test.ts, props.test.ts) - all 73 tests pass.

New tests cover:

  • Doc with explicit frontmatter ID different from filename gets autoGeneratedId
  • Doc with matching frontmatter ID has no autoGeneratedId
  • Doc without frontmatter ID has no autoGeneratedId
  • createDocsByIdIndex indexes by explicit ID
  • createDocsByIdIndex indexes by autoGeneratedId as fallback alias
  • autoGeneratedId alias never overrides an existing explicit ID

(AI-assisted)

…icit ID

When a doc has an explicit front matter id that differs from the
file-path-based id, the autogenerated id is now preserved as a fallback
alias. This means references using the file-path-based id still resolve
to the correct document even after an explicit id is assigned.

Changes:
- Added autoGeneratedId field to DocMetadataBase type
- Computed autoGeneratedId in doProcessDocMetadata when front matter id
  differs from the file name
- Updated createDocsByIdIndex to register autogenerated IDs as fallback
  entries that never override explicit IDs
- Added unit tests for autoGeneratedId computation and index aliasing
- Updated 5 snapshots to reflect the new field on affected docs

(AI-assisted)
@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Mar 3, 2026
@netlify
Copy link

netlify bot commented Mar 3, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 5b3507d
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/69a6eb61d624e900081b3854
😎 Deploy Preview https://deploy-preview-11769--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support autogenerated heading IDs as aliases/fallbacks when explicit IDs are defined

1 participant